package br.com.duosoftware.orcamento.hibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

/**
 *
 * @author Daniel
 * 
 */
  
public class HibernateUtil {
    
    private static HibernateUtil me;
    private SessionFactory sessionFactory;

    public HibernateUtil(){
        sessionFactory = new AnnotationConfiguration().configure("br/com/duosoftware/orcamento/hibernate/hibernate.cfg.xml").buildSessionFactory();
    }

    public Session getSession(){
       Session toReturn = sessionFactory.openSession();
       toReturn.beginTransaction();
       return toReturn;
    }

    public static HibernateUtil getInstance(){
        if(me == null){
            me = new HibernateUtil();
        }
        return me;
    }

}
